/**
 * 
 */
package com.net.dao;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.net.domain.Student;

/**
 * @author Dinesh
 *
 */
public class StudentDao {
	
	final static Logger log = Logger.getLogger(StudentDao.class);
	
	private SqlMapClient sqlMapClient;
	
	@SuppressWarnings("unchecked")
	public List<Student> getAllStudents () {
		List<Student> list = null;
		
		try {
			list = (List<Student>)sqlMapClient.queryForList("getStudents");
		}
		catch (Exception e) {
			log.error("Error caught while retrieving Student details" + e.getMessage(), e);
		}
		
		return list;		
	}
	
	public Student getStudent(int referenceId) {
		Student student = null;
		
		try {
			student = (Student)sqlMapClient.queryForObject("getStudent", referenceId);
		}
		catch (Exception e) {
			log.error("Error caught while retrieving Student details" + e.getMessage(), e);
		}
		
		return student;
	}


	public boolean updateInfo(Student student) {
		int status = 0;
		
		try {
			log.info("Writing the object " + student.toString());
			status = sqlMapClient.update("updateStudentInfo", student);
		}
		catch (Exception e) {
			log.error("Error caught while retrieving Student details" + e.getMessage(), e);
		}
		
		return (status != 0);
	}
	
	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	@Autowired
	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}




}
